package reflect;

import java.io.File;
import java.util.Arrays;


public class Test2 {
    public static void main(String[] args) throws Exception {
       /* File dir = new File(
                Test2.class.getResource(".").toURI()
        );
        String packname = Test2.class.getPackage().getName();
        String[] strings = dir.list();
        System.out.println(dir);
        for (int i = 0; i < strings.length; i++) {
            String[] str = strings[i].split("\\.");
            Class cls = Class.forName(packname+"."+str[0]);
            Object obj = cls.newInstance();
            System.out.println(obj);
        }*/
       File dir = new File(
               Test2.class.getResource(".").toURI()
       );
       String packname = Test2.class.getPackage().getName();
        System.out.println(packname);

        File[] subs = dir.listFiles(f->f.getName().endsWith(".class"));
        for (File sub: subs
             ) {
            String fileName = sub.getName();
            String className = fileName.substring(0,fileName.indexOf("."));
            Class cls = Class.forName(packname+"."+className);
            Object obj = cls.newInstance();
            System.out.println(obj);
        }
    }
}
